Skip to content

Conversation

@mhuggins
Copy link

@mhuggins mhuggins commented Jan 9, 2026

🎯 Changes

Passing an asynchronous function to a synchronous validator (i.e.: onBlur, onChange, onDynamic, onSubmit) is a bit of a foot-gun given that it does not produce any typescript errors, but it also results in the form/field validation function running after the core validation logic.

This updates the types for these validator functions on both FormApi and FieldApi to prevent passing a function that returns a Promise.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2026

🦋 Changeset detected

Latest commit: 6b927d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/form-core Patch
@tanstack/angular-form Patch
@tanstack/form-devtools Patch
@tanstack/lit-form Patch
@tanstack/react-form Patch
@tanstack/solid-form Patch
@tanstack/svelte-form Patch
@tanstack/vue-form Patch
@tanstack/react-form-devtools Patch
@tanstack/solid-form-devtools Patch
@tanstack/react-form-nextjs Patch
@tanstack/react-form-remix Patch
@tanstack/react-form-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Passing an asynchronous function to a synchronous validator (i.e.: `onBlur`, `onChange`,
`onDynamic`, `onSubmit`) is a bit of a foot-gun given that it does not produce any typescript
errors, but it also results in the form/field validation function running after the core
validation logic.

To prevent this, update the types for these validator functions on both `FormApi` and
`FieldApi` to prevent passing a function that returns a `Promise`.
@mhuggins mhuggins force-pushed the prevent-synchronous-promises branch from 5924423 to 2198362 Compare January 9, 2026 15:57
@nx-cloud
Copy link

nx-cloud bot commented Jan 10, 2026

View your CI Pipeline Execution ↗ for commit 6b927d2

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 53s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-10 17:34:24 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 10, 2026

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1987

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1987

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@1987

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1987

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1987

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@1987

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@1987

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@1987

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@1987

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1987

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@1987

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1987

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1987

commit: 6b927d2

@mhuggins
Copy link
Author

Just pushed an update that should address the lint issue, sorry about that!

Comment on lines +13 to +21
export type RejectPromiseValidator<T> = T extends (...args: any[]) => infer R
? // Check if R is `any` - if so, allow it (common with mocks)
0 extends 1 & R
? T
: // Otherwise, reject if it's a Promise
[R] extends [Promise<any> | PromiseLike<any>]
? never
: T
: T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this truly needed? Can the return type not be Omit<T, Promise<any> | PromiseLike<any>>?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you mean Exclude rather than Omit, but no that does not work here. I believe it is a limitation of TypeScript, but the type is still treated as unknown it seems even if attempting to approach it from this angle.

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.46%. Comparing base (6892ed0) to head (6b927d2).
⚠️ Report is 117 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1987      +/-   ##
==========================================
- Coverage   90.35%   89.46%   -0.90%     
==========================================
  Files          38       48      +10     
  Lines        1752     1945     +193     
  Branches      444      488      +44     
==========================================
+ Hits         1583     1740     +157     
- Misses        149      184      +35     
- Partials       20       21       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants